package com.google.code.p.restrpc.core;

import java.util.Arrays;
import java.util.Date;
import java.util.UUID;

public class RpcServiceMetadata {
    
    /*
     * The identify
     */
    private String key;
    
    /*
     * The name of service
     */
    private String serviceName;
    
    /*
     * The super interface of service bean
     */
    private Class[] serviceInterfaces;
    
    /*
     * The implementor class of service bean
     */
    private Class serviceClass;
    
    /*
     * The remote service bean
     */
    private Object service;
    
    /*
     * The original bean of remote service
     */
    private Object target;
    
    /*
     * 
     */
    private String description;
    
    /*
     * 
     */
    private Date exportDateTime;
    
    private boolean exported = false;
    
    public RpcServiceMetadata() {
        this.key = UUID.randomUUID().toString();
    }
    
    public RpcServiceMetadata(String serviceName,
                              Class serviceClass,
                              Class[] serviceInterface,
                              Object service,
                              Object target) {
        this.key = UUID.randomUUID().toString();
        this.serviceName = serviceName;
        this.serviceClass = serviceClass;
        this.serviceInterfaces = serviceInterface;
        this.service = service;
        this.target = target;
    }
    
    public RpcServiceMetadata(String serviceName,
                              Class serviceClass,
                              Class serviceInterface,
                              Object service,
                              Object target) {
        this.key = UUID.randomUUID().toString();
        this.serviceName = serviceName;
        this.serviceClass = serviceClass;
        this.serviceInterfaces = new Class[] { serviceInterface };
        this.service = service;
        this.target = target;
    }
    
    /**
     * @return the key
     */
    public String getKey() {
        return key;
    }
    
    /**
     * @param key
     *            the key to set
     */
    public void setKey(String key) {
        this.key = key;
    }
    
    /**
     * @return the serviceName
     */
    public String getServiceName() {
        return serviceName;
    }
    
    /**
     * @param serviceName
     *            the serviceName to set
     */
    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }
    
    /**
     * @return the serviceInterfaces
     */
    public Class[] getServiceInterfaces() {
        return serviceInterfaces;
    }
    
    /**
     * @param serviceInterfaces
     *            the serviceInterfaces to set
     */
    public void setServiceInterfaces(Class[] serviceInterfaces) {
        this.serviceInterfaces = serviceInterfaces;
    }
    
    public void setServiceInterfaces(Class serviceInterface) {
        this.serviceInterfaces = new Class[] { serviceInterface };
    }
    
    /**
     * @return the implementorClass
     */
    public Class getServiceClass() {
        return serviceClass;
    }
    
    /**
     * @param implementorClass
     *            the implementorClass to set
     */
    public void setServiceClass(Class implementorClass) {
        this.serviceClass = implementorClass;
    }
    
    /**
     * @return the service
     */
    public Object getService() {
        return service;
    }
    
    /**
     * @param service
     *            the service to set
     */
    public void setService(Object service) {
        this.service = service;
    }
    
    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }
    
    /**
     * @param description
     *            the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }
    
    /**
     * @return the exportDateTime
     */
    public Date getExportDateTime() {
        return exportDateTime;
    }
    
    /**
     * @param exportDateTime
     *            the exportDateTime to set
     */
    public void setExportDateTime(Date exportDateTime) {
        this.exportDateTime = exportDateTime;
    }
    
    /**
     * @param exported
     *            the exported to set
     */
    public void setExported(boolean exported) {
        this.exported = exported;
    }
    
    public boolean isExported() {
        return this.exported;
    }
    
    public void export() {
        this.exported = true;
        this.exportDateTime = new Date();
    }
    
    public void unexport() {
        this.exported = false;
    }
    
    public String toString() {
        return "RpcServiceMetadata [serviceName=" + serviceName
               + ", description="
               + description
               + ", serviceInterfaces="
               + Arrays.toString(serviceInterfaces)
               + "]";
    }
    
}
